<?php session_start(); //Session ?>
<?php include_once( "_db.php" ); //Database ?>
<?php include_once( "funcdef.php" ); //Functions Definition ?>
<?php include_once( "header.php" ); //Header ?>
<?php include_once( "footer.php" ); //Footer ?>
<?php
//include page header
header_template("Checkout", $_SERVER['PHP_SELF'], "icon-shopping-cart");
?>
      <div class="row">
        <div class="span6">
<?php
if (!empty($_SESSION['shoppingBag'])) {
  //Bag check OK

  //db OBJECT invoked!
  $db = new DATABASE();

  if(!isset($_SESSION['checkOut'])) {
    $_SESSION['checkOut'] = array();
  }

  /*
  $_SESSION['checkOut']['state']
  Checkout -> 01 Signin
  Checkout -> 02 Contacts
  Checkout -> 03 Bag
  Checkout -> 04 Order
  Checkout -> 05 Payment
  */
  if(!isset($_SESSION['checkOut']['state'])) {
    $_SESSION['checkOut']['state'] = "01";
  }

  if(!isset($_SESSION['checkOut']['logintype'])) {
    $_SESSION['checkOut']['logintype'] = "GUEST";
  }

  if (isset($_REQUEST['guest'])) {
    $_SESSION['checkOut']['logintype'] = "GUEST";
  }
  if (isset($_REQUEST['google'])) {
    $_SESSION['checkOut']['logintype'] = "GOOGLE";
  }
  if (isset($_REQUEST['twitter'])) {
    $_SESSION['checkOut']['logintype'] = "TWITTER";
  }
  if (isset($_REQUEST['facebook'])) {
    $_SESSION['checkOut']['logintype'] = "FACEBOOK";
  }

  if ($_REQUEST["do"] == "signin") {
    $_SESSION['checkOut']['state'] = "01";
  } elseif ($_REQUEST["do"] == "contacts") {
    $_SESSION['checkOut']['state'] = "02";
  } elseif ($_REQUEST["do"] == "bag") {
    $_SESSION['checkOut']['state'] = "03";
  } elseif ($_REQUEST["do"] == "order") {
    $_SESSION['checkOut']['state'] = "04";
  } elseif ($_REQUEST["do"] == "pay") {
    $_SESSION['checkOut']['state'] = "05";
  } else {
  }

  $pgntn_state_01 = "";
  $pgntn_state_02 = "";
  $pgntn_state_03 = "";
  $pgntn_state_04 = "";
  $pgntn_state_05 = "";
  switch ($_SESSION['checkOut']['state']) {
    case '01':
      $pgntn_state_01 = " badge-info";
      break;
    case '02':
      $pgntn_state_02 = " badge-info";
      break;
    case '03':
      $pgntn_state_03 = " badge-info";
      break;
    case '04':
      $pgntn_state_04 = " badge-info";
      break;
    case '05':
      $pgntn_state_05 = " badge-info";
      break;
    default:
      break;
  }
?>
          <hr />
            <span class="badge<?php echo $pgntn_state_01; ?>">Sign-in</span>&nbsp;&rarr;
            <span class="badge<?php echo $pgntn_state_02; ?>">Contacts</span>&nbsp;&rarr;
            <span class="badge<?php echo $pgntn_state_03; ?>">Bag</span>&nbsp;&rarr;
            <span class="badge<?php echo $pgntn_state_04; ?>">Order</span>&nbsp;&rarr;
            <span class="badge<?php echo $pgntn_state_05; ?>">Payment</span>
          <hr />
<?php
  switch ($_SESSION['checkOut']['state']) {
    case '01':
      include_once( "checkout01signin.php" ); //Checkout -> 01 Signin
      break;
    case '02':
      include_once( "checkout02contacts.php" ); //Checkout -> 02 Contacts
      break;
    case '03':
      include_once( "checkout03bag.php" ); //Checkout -> 03 Bag
      break;
    case '04':
      include_once( "checkout04order.php" ); //Checkout -> 04 Order
      break;
    case '05':
      include_once( "checkout05payment.php" ); //Checkout -> 05 Payment
      break;
    default:
      break;
  }

} else {
  //Bag check NG

  if(isset($_SESSION['checkOut'])) {
    unset($_SESSION['checkOut']);
  }

  if(isset($_SESSION['checkOut']['state'])) {
    unset($_SESSION['checkOut']['state']);
  }

  if(isset($_SESSION['checkOut']['logintype'])) {
    unset($_SESSION['checkOut']['logintype']);
  }

  printAlert("error", "Oh snap!", "Bag is empty.", "#");
  printContinueShopping("#");
}
  /*
  echo "<pre>\n";
  print_r($_SESSION);
  print_r($bagProd);
  print_r($bagUnique);
  print_r($prodIdsUnique);
  print_r($bagCount);
  print_r($queries);
  echo "</pre>\n";
  */
?>
        </div>
      </div>
<?php
//include page footer
footer_template();
?>